package cn.qn.controller.team;

import cn.qn.base.PageVO;
import cn.qn.dto.ResponseDTO;
import cn.qn.dto.team.RecruitDTO;
import cn.qn.dto.team.RecruitQueryDTO;
import cn.qn.exceptions.BizException;
import cn.qn.framwork.security.MemberAccountUtils;
import cn.qn.service.team.RecruitService;
import com.alibaba.dubbo.config.annotation.Reference;
import org.springframework.web.bind.annotation.*;

/**
 * @author: Bryant
 * @date: 2019/5/29
 * @description:
 */
@RestController
@RequestMapping("/recruit")
public class RecruitController {

    @Reference(check = false,timeout = 30000)
    private RecruitService recruitService;

    @RequestMapping(value = "/list" ,name="招聘列表接口",method = RequestMethod.GET)
    public ResponseDTO list( RecruitQueryDTO query){
        PageVO<RecruitDTO> recruits = recruitService.pageQueryRecruits(query);
        return ResponseDTO.success(recruits);
    }

    @RequestMapping(value = "/detail/{id}" ,name="招聘详情接口",method = RequestMethod.GET)
    public ResponseDTO detail(@PathVariable(value = "id") Integer id){
        RecruitDTO recruit = recruitService.queryDetailById(id);
        return ResponseDTO.success(recruit);
    }

    @RequestMapping(value = "/add" ,name="发布招聘接口",method = RequestMethod.POST)
    public ResponseDTO add(@RequestBody RecruitDTO dto){
        try {
            dto.setOperator(MemberAccountUtils.getCurrentMember().getUsername());
            recruitService.addRecruit(dto);
            return ResponseDTO.success();
        }catch (BizException e){
            return ResponseDTO.error(e.getMessage());
        }
    }
    @RequestMapping(value = "/edit" ,name="修改招聘信息接口",method = RequestMethod.POST)
    public ResponseDTO edit(@RequestBody RecruitDTO dto){
        try {
            dto.setOperator(MemberAccountUtils.getCurrentMember().getUsername());
            recruitService.editRecruit(dto);
            return ResponseDTO.success();
        }catch (BizException e){
            return ResponseDTO.error(e.getMessage());
        }
    }
    @RequestMapping(value = "/edit/status" ,name="修改招聘状态接口",method = RequestMethod.POST)
    public ResponseDTO editStatus(@RequestBody RecruitDTO dto){
        try {
            dto.setOperator(MemberAccountUtils.getCurrentMember().getUsername());
            recruitService.editStatus(dto);
            return ResponseDTO.success();
        }catch (BizException e){
            return ResponseDTO.error(e.getMessage());
        }
    }
    @RequestMapping(value = "/delete/{id}" ,name="删除招聘信息接口",method = RequestMethod.POST)
    public ResponseDTO deleteRecruit(@PathVariable(value = "id") Integer id){
        try {
            recruitService.deleteRecruit(id);
            return ResponseDTO.success();
        }catch (BizException e){
            return ResponseDTO.error(e.getMessage());
        }
    }
}
